<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>抽奖2</title>
		<style>
			* {
				margin: 0;
				padding: 0;
			}
			
			div {
				margin: 50px auto;
				text-align: center;
			}
			
			img {
				margin-bottom: 20px;
			}
			
			input[type=button] {
				height: 50px;
				width: 100px;
				border-radius: 20px;
				background: pink;
			}
		</style>
	</head>

	<body>
		<div>
			<img src="imges/1.jpg" id="who" />
			<br />
			<input type="button" value="谁是幸运儿" id="choujiang" />
		</div>

		<script>
			var pics = ["1", "2", "3", "4", "5", "6", "7", "8"];
			
			var timer;
			//alert(num);
			 choujiang.onclick=function() {
				if(choujiang.value == "停") {
					clearInterval(timer);
					choujiang.value = "谁是幸运儿";
				} else {
					timer = setInterval(f,80);
					choujiang.value = "停";
				}

			};

			function f() {
				var num =(Math.floor(Math.random() * pics.length));
				who.src = "imges/" + pics[num]+ ".jpg";
			}
			//setInterval(choujiang,10);
		</script>
	</body>

</html>